home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 1.6 KB | 81 lines |
- package symantec.itools.lang;
-
-
- import java.applet.Applet;
- import java.net.URL;
-
-
- public class Context
- {
- private static Applet applet;
- private static URL documentBase;
- private static boolean initialized = false;
-
- public static boolean isApplet()
- {
- return applet != null;
- }
-
- public static boolean isApplication()
- {
- return applet == null;
- }
-
- public static void setApplet(Applet a)
- {
- applet = a;
- initialized = true;
- }
-
- public static Applet getApplet()
- {
- return applet;
- }
-
- public static void setDocumentBase(URL db)
- {
- documentBase = db;
- initialized = true;
- }
-
- private static void initializeApp()
- {
- StringBuffer p = new StringBuffer(System.getProperty("user.dir"));
- int pl = p.length();
-
- // If the system file separator isn't the URL file separator convert it.
- try
- {
- char ps = (System.getProperty("file.separator")).charAt(0);
- if(ps != '/')
- for(int counter = 0; counter < pl; counter++)
- {
- if(ps == p.charAt(counter)) p.setCharAt(counter, '/');
- }
- } catch(StringIndexOutOfBoundsException e) {}
-
- try {
- documentBase = new URL("file://" + p + "/");
- } catch (java.net.MalformedURLException e) {
- }
- }
-
- public static URL getDocumentBase()
- {
- if (! initialized) {
- initializeApp();
- initialized = true;
- }
-
- if(documentBase != null)
- {
- return documentBase;
- }
- else if (applet != null)
- {
- return applet.getDocumentBase();
- }
-
- return null;
- }
- }